package com.ssy.lingxi.purchase.entity.onlinebidding;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.purchase.api.dto.request.EnclosureUrlsRequest;
import com.ssy.lingxi.purchase.api.dto.response.online.CountryArea;
import com.ssy.lingxi.purchase.entity.converter.JpaJsonToCountryAreaConverter;
import com.ssy.lingxi.purchase.entity.converter.JpaJsonToCountryAreaListConverter;
import com.ssy.lingxi.purchase.entity.converter.JpaJsonToEnclosureUrlsRequestListConverter;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

/**
 * 报价明细
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "pu_on_line_materiel")
public class OnlineMateriel {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "on_line_materiel_seq")
    @SequenceGenerator(sequenceName = "pu_on_line_materiel_seq", name = "on_line_materiel_seq", allocationSize = 1)
    private Long id;

    /**
     * 在线竞价信息
     */
    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name = "onlineBidding_id", referencedColumnName = "id")
    private OnLineBidding onlineBidding;

    /**
     *报名会员id
     */
    @Column
    private Long createMemberId;

    /**
     *报名会员名称
     */
    @Column
    private String createMemberName;

    /**
     *报名会员角色id
     */
    @Column
    private Long createMemberRoleId;

    /**
     *电子邮箱
     */
    private String mail;

    /**
     * 联系电话
     */
    private String tel;

    /**
     * 联系电话前缀ID
     */
    private Long telPrefix;

    /**
     * 联系人
     */
    private String contacts;

    /**
     *详细地址
     */
    private String address;

    /**
     * 地址
     */
    @Convert(converter = JpaJsonToCountryAreaListConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<CountryArea> areas;

    /**
     * 报名地址
     */
    @Convert(converter = JpaJsonToCountryAreaConverter.class)
    @Column(columnDefinition = "jsonb")
    private CountryArea signUpAreas;

    /**
     * 竞价物料信息
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "onlineMateriel", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private List<OnLineBiddingProduct> products;

    /**
     *报名时间
     */
    private Long signUpTime;

    /**
     *报名文件
     */
    @Convert(converter = JpaJsonToEnclosureUrlsRequestListConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<EnclosureUrlsRequest> enclosureUrls;

    /**
     * 在线内部流转
     */
    private Integer interiorState;

    /**
     * 在线外部流转
     */
    private Integer externalState;

    /**
     * 在线审核内部流转 在 OnlineAudteInteriorStateEnum 中定义 1:待审核竞价报名; 2:已审核竞价报名
     * 已报名则状态为待审核竞价报名 采购会员已审核则状态为已审核竞价报名
     */
    private Integer interiorAdutState;

    /**
     * 在线审核外部流转 在 OnlineAudteExternalStateEnum 中定义 1:待审核竞价报名; 2:竞价报名审核不通过; 3:竞价报名审核通过
     * 已报名则状态为待审核竞价报名
     */
    private Integer externalAdutState;

    /**
     *最终排名
     */
    private Long purchaseRanking;

    /**
     *是否中标: 1 中标，0 不中标
     */
    private Integer isPrize=0;

    /**
     *是否报过价: 1 已报价，0 未报价
     */
    private Integer isOffer=0;

    /**
     *是否报名: 1 已报名，0 未报名
     */
    private Integer isSignUp=0;

    /**
     *报价次数
     */
    private Long peportPriceSum;

    /**
     * 最后竞标的授标金额(含税)
     */
    private Double price;

    /**
     * 当前竞价总金额
     */
    private Double sumPrice;

    /**
     * 最后报价时间
     */
    private Long reportTime;
}
